// DlgFaceSetting.cpp : implementation file
//

#include "stdafx.h"
#include "CStudyChinese.h"
#include "DlgFaceSetting.h"
#include "AppSetting.h"
#include "FaceManager.h"
#include "FaceHandler.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgFaceSetting dialog


CDlgFaceSetting::CDlgFaceSetting(CWnd* pParent /*=NULL*/)
	: CTabDlg(CDlgFaceSetting::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgFaceSetting)
	m_strDes = _T("");
	//}}AFX_DATA_INIT
}


void CDlgFaceSetting::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgFaceSetting)
	DDX_Control(pDX, IDC_LIST_THEMES, m_lsThemes);
	DDX_Control(pDX, IDC_CB_SR_FONT, m_cbSrFont);
	DDX_Control(pDX, IDC_CB_SR_BK, m_cbSrBK);
	DDX_Control(pDX, IDC_CB_GW_FONT, m_cbGwFont);
	DDX_Control(pDX, IDC_CB_GW_BK, m_cbGwBK);
	DDX_Text(pDX, IDC_STATIC_DES, m_strDes);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgFaceSetting, CTabDlg)
	//{{AFX_MSG_MAP(CDlgFaceSetting)
	ON_LBN_SELCHANGE(IDC_LIST_THEMES, OnSelchangeListThemes)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgFaceSetting message handlers

void CDlgFaceSetting::SaveUpdateSetting()
{
	CAppSetting::Instance()->m_SrFontColor = m_cbSrFont.GetSelectedColorValue() ;
	CAppSetting::Instance()->m_SrBKColor = m_cbSrBK.GetSelectedColorValue();
	CAppSetting::Instance()->m_GwFontColor = m_cbGwFont.GetSelectedColorValue() ;
	CAppSetting::Instance()->m_GwBKColor = m_cbGwBK.GetSelectedColorValue();
	UINT nCurSel = m_lsThemes.GetCurSel() ;
	if(nCurSel!= LB_ERR)
	{
		CAppSetting::Instance()->m_nCurTheme = nCurSel;
		
		if(nCurSel>=CFaceManager::Instance()->m_nThemeCount)
		{
			CFaceHandler::Instance()->SetCurSkin(nCurSel-CFaceManager::Instance()->m_nThemeCount);
		}
		else
		{
			CFaceManager::Instance()->SetCurTheme(nCurSel);
		}
	}
}

BOOL CDlgFaceSetting::OnInitDialog() 
{
	CTabDlg::OnInitDialog();
    m_cbSrFont.InitializeDefaultColors();
	m_cbSrBK.InitializeDefaultColors();
    m_cbGwFont.InitializeDefaultColors();
	m_cbGwBK.InitializeDefaultColors();

	m_cbSrFont.SetSelectedColorValue(CAppSetting::Instance()->m_SrFontColor);
	m_cbSrBK.SetSelectedColorValue(CAppSetting::Instance()->m_SrBKColor);		
	m_cbGwFont.SetSelectedColorValue(CAppSetting::Instance()->m_GwFontColor);
	m_cbGwBK.SetSelectedColorValue(CAppSetting::Instance()->m_GwBKColor);	
	
	
	CFaceManager* p = CFaceManager::Instance();
	CTheme* pTheme = NULL;
	for(UINT i = 0 ; i<p->m_nThemeCount ;i++)
	{
		pTheme = p->GetTheme(i);
		m_lsThemes.AddString(pTheme->m_strThemeName);
	}
	CFaceHandler* ph = CFaceHandler::Instance() ;
	CSkin* pSkin = NULL ;
	for(i=0;i<ph->m_nSkinCount;i++)
	{
		pSkin = ph->GetSkin(i);
		m_lsThemes.AddString(pSkin->m_strSkinName);
	}
	m_lsThemes.SetCurSel(CAppSetting::Instance()->m_nCurTheme);
	OnSelchangeListThemes();
	return TRUE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgFaceSetting::OnSelchangeListThemes() 
{
	CTheme* pTheme = NULL;	
	UINT nCurSel = m_lsThemes.GetCurSel() ;
	if(nCurSel!=LB_ERR)
	{
		if(nCurSel>=CFaceManager::Instance()->m_nThemeCount)
		{
			m_strDes = CFaceHandler::Instance()->GetSkin(nCurSel-CFaceManager::Instance()->m_nThemeCount)->m_strSkinDes;
		}
		else
		{
			pTheme = CFaceManager::Instance()->GetTheme(nCurSel);
			m_strDes = pTheme->m_strThemeDes;
		}
		UpdateData(FALSE);
	}
}

